package com.homer.android.sdk.action.device.common;

import com.homer.android.sdk.command.uart.EspCommandUartGetStatusInternet;
import com.homer.android.sdk.command.uart.IEspCommandUartGetStatusInternet;
import com.homer.android.sdk.devcie.IEspDevice;

import com.homer.android.sdk.devcie.IEspDeviceUart;

import com.homer.android.sdk.devcie.status.IEspStatusUart;
import com.homer.iot.esptouch.udp.EspDeviceType;

public class EspActionDeviceGetStatusInternet implements IEspActionDeviceGetStatusInternet
{
    
    @Override
    public IEspStatusUart doActionDeviceGetStatusInternet(IEspDevice device)
    {
        EspDeviceType deviceType = device.getDeviceType();
        String deviceNumber = device.getDeviceNumber();
       
        switch (deviceType)
        {
            case UART:
                IEspCommandUartGetStatusInternet uartCommand = new EspCommandUartGetStatusInternet();
                IEspStatusUart uartStatus = uartCommand.doCommandUartGetStatusInternet(deviceNumber);
                if (uartStatus != null)
                {                  
                    IEspDeviceUart deviceUart = (IEspDeviceUart)device;
                    deviceUart.getStatusUart().setIsDefenceOn(uartStatus.isDefenceOn());
                    deviceUart.getStatusUart().setIsLightOn(uartStatus.isLightOn());
                    deviceUart.getStatusUart().setIsOnline(uartStatus.isOnline());
                }               
                return uartStatus;
        }
        throw new IllegalArgumentException();
    }
    
}
